package canhcuadaihoc.tracnghiemonline;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
	static boolean _chk_bookmark=false;
	static boolean _chk_like=false;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newspage_details);
        
        //Xử lí lệnh Like
        final Button bt_like=(Button)findViewById(R.id.bt_like);
        bt_like.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(_chk_like==true)
				{
					Toast.makeText(getApplicationContext(), "UnLiked", Toast.LENGTH_SHORT).show();
					_chk_like=false;
					bt_like.setBackgroundResource(R.drawable.ratinggood);
				}
				else
				{
					Toast.makeText(getApplicationContext(), "Liked", Toast.LENGTH_SHORT).show();
					_chk_like=true;
					bt_like.setBackgroundResource(R.drawable.ratingbad);
				}
			}
		});
    }
    
    //Tạo menu hiển thị tính năng đánh dấu
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	// TODO Auto-generated method stub
    	menu.add(0, 0, 0, "Bookmark").setIcon(R.drawable.ratingimportant);
    	menu.add(0, 1, 0, "Unbookmark").setIcon(R.drawable.ratingnotimportant);
    	return super.onCreateOptionsMenu(menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	// TODO Auto-generated method stub
    	switch (item.getItemId()) {
		case 0:
			if(_chk_bookmark==true){
				Toast.makeText(this.getApplicationContext(), "Đã đánh dấu trước đó", Toast.LENGTH_SHORT).show();	
			}
			else
			{
				_chk_bookmark=true;
				Toast.makeText(this.getApplicationContext(), "Đã đánh dấu", Toast.LENGTH_SHORT).show();
			}
				
			break;
		case 1:
			if(_chk_bookmark==true)
			{
				Toast.makeText(this.getApplicationContext(), "Đã gỡ đánh dấu", Toast.LENGTH_SHORT).show();
				_chk_bookmark=false;
			}
			else
			{
				Toast.makeText(this.getApplicationContext(), "Bạn chưa đánh dấu trước đó", Toast.LENGTH_SHORT).show();
			}
		default:
			break;
		}
    	return super.onOptionsItemSelected(item);
    }
}